/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package UserGroup;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Stack;
import java.util.Vector;

/**
 *
 * @author Mukesh
 */
public class Query {

    static Connection con = null;

    public static int addgroup(UserGroupBean ugb) {
        int i = 0;

        try {
            con = DBConnection.Connection.getConnection();
            PreparedStatement pre = con.prepareStatement("insert into groups values(GROUPID.nextval,?,?,sysdate)");
            pre.setString(1, ugb.getGroupName());
            pre.setString(2, ugb.getUserType());
            i = pre.executeUpdate();
        } catch (Exception e) {
            System.out.println(e);
        }
        return i;
    }

    public static Vector viewAll() {
        ResultSet rs;
        Vector<UserGroupBean> list = new Stack<UserGroupBean>();
        try {
            con=DBConnection.Connection.getConnection();
            PreparedStatement pre=con.prepareStatement("select * from groups");
            rs=pre.executeQuery();
            while(rs.next()){
                UserGroupBean ugb=new UserGroupBean();
                ugb.setGroup_id(rs.getInt(1));
                ugb.setGroupName(rs.getString(2));
                ugb.setUserType(rs.getString(3));
                ugb.setEntrydate(rs.getDate(4));
                list.add(ugb);
            }
        } catch (Exception e) {
            System.err.println();
        }
        return list;
    }
}
